//
//  DetailTableViewController.m
//  Table_fresh
//
//  Created by NS Chuong on 25/10/12.
//  Copyright (c) 2012 Tamsao. All rights reserved.
//

#import "DetailTableViewController.h"

@interface DetailTableViewController ()

@end

@implementation DetailTableViewController

@synthesize subjectDetailImages,subjectName, subjectNumber ,bannerIsVisible2, d, cellHeight;


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    switch (subjectNumber)
    {
            
        case 0:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"1Slide1.png",
                                        @"1Slide2.png",
                                        @"1Slide3.png",
                                        @"1Slide4.png",
                                        @"1Slide5.png",
                                        @"1Slide6.png",nil];
            
            
            break;

        case 1:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"2Slide1.png",
                                        @"2Slide2.png",
                                        @"2Slide3.png",
                                        @"2Slide4.png",
                                        @"2Slide5.png",
                                        @"2Slide6.png",
                                         @"2Slide7.png",
                                         @"2Slide8.png",nil];
            break;
        case 2:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"3Slide1.png",
                                        @"3Slide2.png",
                                        @"3Slide3.png",
                                        @"3Slide4.png",
                                        @"3Slide5.png",
                                        @"3Slide6.png",
                                        @"3Slide7.png",
                                        @"3Slide8.png",
                                        @"3Slide9.png",nil];
            break;
        case 3:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"4Slide1.png",
                                        @"4Slide2.png",
                                        @"4Slide3.png",
                                        @"4Slide4.png",
                                        @"4Slide5.png",
                                        @"4Slide6.png",
                                        @"4Slide7.png",
                                         @"4Slide8.png",nil];
            
            break;
            
        case 4:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"5Slide1.png",
                                        @"5Slide2.png",
                                        @"5Slide3.png",
                                        @"5Slide4.png",
                                        @"5Slide5.png",
                                        @"5Slide6.png",
                                        @"5Slide7.png",nil];
            
            break;
        case 5:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"6Slide1.png",
                                        @"6Slide2.png",
                                        @"6Slide3.png",
                                        @"6Slide4.png",nil];
            
            break;
        case 6:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"7Slide1.png",
                                        @"7Slide2.png",
                                        @"7Slide3.png",
                                        @"7Slide4.png",
                                        @"7Slide5.png",
                                        @"7Slide6.png",
                                        @"7Slide7.png",nil];
            
            break;
            
        case 7:
            self.subjectDetailImages = [[NSArray alloc]
                                        initWithObjects:@"AboutVNLite.png",nil];
                                    
            break;

            
        default:
            break;
            
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return subjectDetailImages.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellDetail";
    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (!cell1) {
        cell1 = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
    }
    
    // Configure the cell...
    
    
    self.title= subjectName;
    
    UIImage *DetailPhoto = [UIImage imageNamed: [self.subjectDetailImages objectAtIndex: [indexPath row]]];
    cell1.imageView.image=DetailPhoto;
        
    
    
    return cell1;
}


- (CGFloat) tableView: (UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath  *) indexPath
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    
    
    UIImage *DetailPhoto = [UIImage imageNamed: [self.subjectDetailImages objectAtIndex: [indexPath row]]];
    if (orientation == UIDeviceOrientationLandscapeLeft ||
        orientation == UIDeviceOrientationLandscapeRight)
    {
        d=480;
    }
    
    else
        d=320;
    
    
    cellHeight=(d*(DetailPhoto.size.height/DetailPhoto.size.width));
    
    
    return cellHeight;
}
#pragma mark -
#pragma mark -TableView Delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"asdasd");
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if(!self.bannerIsVisible2)
    {
        
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1];
        [banner setAlpha:1];
        // Assumes the banner view is just off the bottom of the screen.
        //banner.frame = CGRectOffset(banner.frame, 0, self.view.frame.size.height-50);
        banner.frame = CGRectOffset(banner.frame, 0,0);
        
        [UIView commitAnimations];
        
        self.bannerIsVisible2 = YES;
    }
    
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if(!self.bannerIsVisible2)
    {
        
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1];
        [banner setAlpha:0];
        // Assumes the banner view is just off the bottom of the screen.
        //banner.frame = CGRectOffset(banner.frame, 0, self.view.frame.size.height-50);
        //  banner.frame = CGRectOffset(banner.frame, 0, 50.0f);
        [UIView commitAnimations];
        
        self.bannerIsVisible2 = NO;
    }
}


/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */

/*
 // Override to support editing the table view.
 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
 if (editingStyle == UITableViewCellEditingStyleDelete) {
 // Delete the row from the data source
 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
 }
 else if (editingStyle == UITableViewCellEditingStyleInsert) {
 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
 }
 }
 */

/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */

#pragma mark - Table view delegate
/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
 
}    */

@end
